<?php

App::uses('AppModel',    'Model');
App::uses('CakeSession', 'Model/Datasource');

class Contact extends AppModel {
    
    public $useTable = false;
    
    public static $captchaKey = 'captcha';
    
    public $validate = array(
        'name' => array(
            'rule'    => 'notEmpty',
            'message' => 'Morate uneti Vaše ime i prezime.'
        ),
        'email' => array(
            array(
                'rule'    => 'notEmpty',
                'message' => 'Morate uneti Vašu e-mail adresu.'
            ),
            array(
                'rule'    => 'email',
                'message' => 'Uneta e-mail adresa nije validna.'
            )
        ),
        'message' => array(
            'rule'    => 'notEmpty',
            'message' => 'Morate uneti poruku.'
        ),
        'captcha' => array(
            'rule'    => array('isCaptchaCorrect'),
            'message' => 'Uneti sigurnosni tekst nije isti kao na slici.'
        )
    );
    
    public function isCaptchaCorrect($data) {
        $captcha = CakeSession::read(self::$captchaKey);
        
        return strtolower($captcha) == strtolower($data['captcha']);
    }
    
}
